<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@include file="/ui/jsp/includes/includes.jspf" %> 

<script type="text/javascript">
    function addNewCategory()
    {
        $('#addNewCategoryForm').attr('action', 'addNewCategory.html');
        $('#addNewCategoryForm').submit();
    }
    function updateCategory()
    {
        $('#categoryId').val('${category.categoryId}');
        $('#addNewCategoryForm').attr('action', 'updateCategory.html');
        $('#addNewCategoryForm').submit();
    }
    function backToCategoryList()
    {
        $('#addNewCategoryForm').attr('action', 'viewCategoryList.html');
        $('#addNewCategoryForm').submit();
    }

</script>

<%@include file="/ui/jsp/includes/header.jspf"%>

<div class="hero-unit secondary_container">
    <div id="table-subject-header">
        <c:if test="${!empty category.categoryName}">
        	Update Category
        </c:if>
        <c:if test="${empty category.categoryName}">
        	Add Category
        </c:if>
    </div>
    <hr>
            
    <div class="row-fluid">
        <form:form method="POST" id="addNewCategoryForm" commandName="category"  class="form-horizontal">
            <form:errors path="*" cssClass="errorblock" element="div"/>
            <div class="control-group">
                <label class="control-label" for="categoryName">Category Name*</label>
                <div class="controls">
                    <form:input id="categoryName" path="categoryName"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="description">Description*</label>
                <div class="controls">
                    <form:input id="description" path="description"/>
                </div>
            </div>
            <div>*Required Fields</div>
            <div class="control-group">
                <div class="controls">
                    <c:choose>
                        <c:when test="${!empty category.categoryId}">
                            <form:hidden path="categoryId" id="categoryId"/>
                            <input type="button" onclick="javascript:updateCategory()" value="Submit" class="btn btn-primary"/>
                        </c:when>
                        <c:otherwise>
                            <input type="button" onclick="javascript:addNewCategory()" value="Submit" class="btn btn-primary"/>
                        </c:otherwise>
                    </c:choose>
                    <input type="button" value="Cancel" onclick="javascript:backToCategoryList()" class="btn btn-primary"/>
                </div>
            </div>

        </form:form>
    </div>
</div>
<%@include file="/ui/jsp/includes/footer.jspf"%>

